package io.gbznt.modules.buss.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.gbznt.modules.sys.entity.SysDeptEntity;
import io.gbznt.modules.sys.service.SysDeptService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import io.gbznt.common.utils.PageUtils;
import io.gbznt.common.utils.Query;

import io.gbznt.modules.buss.dao.BussFarmlandAreaDao;
import io.gbznt.modules.buss.entity.BussFarmlandAreaEntity;
import io.gbznt.modules.buss.service.BussFarmlandAreaService;


@Service("bussFarmlandAreaService")
public class BussFarmlandAreaServiceImpl extends ServiceImpl<BussFarmlandAreaDao, BussFarmlandAreaEntity> implements BussFarmlandAreaService {

    @Autowired
    private SysDeptService sysDeptService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String name = (String)params.get("name");

        IPage<BussFarmlandAreaEntity> page = this.page(
                new Query<BussFarmlandAreaEntity>().getPage(params),
                new QueryWrapper<BussFarmlandAreaEntity>()
                    .like(StringUtils.isNotEmpty(name),"name",name)
        );

        for(BussFarmlandAreaEntity framlaAreaEntity: page.getRecords()){
            SysDeptEntity sysDeptEntity = sysDeptService.getById(framlaAreaEntity.getDeptId());
            if (null!=sysDeptEntity) {
                framlaAreaEntity.setDeptName(sysDeptEntity.getName());
            }

        }

        return new PageUtils(page);
    }

}
